package com.project.common.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.project.common.entity.PageVo;
import com.project.common.entity.SysAuthorization;
import com.project.common.entity.SysRoles;
import com.project.common.mapper.SysAuthorizationMapper;
import com.project.common.service.SysAuthorizationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

@Transactional
@Service
public class SysAuthorizationImpl implements SysAuthorizationService {
    @Autowired
    private SysAuthorizationMapper sysAuthorizationMapper;
    @Override
    public PageVo<SysAuthorization> queryAllSysAuthorization(Map<String,String> map) {
        Integer pageNum = Integer.valueOf(map.get("pageNum"));
        Integer pageSize= Integer.valueOf(map.get("pageSize"));
//        System.out.println(map);
        PageHelper.startPage(pageNum,pageSize);
        List<SysAuthorization> sysAuthorizations = sysAuthorizationMapper.queryAllSysAuthorization();

        PageInfo<SysAuthorization> pageInfo = new PageInfo<SysAuthorization>(sysAuthorizations);

        PageVo<SysAuthorization> pageVo = new PageVo<SysAuthorization>();
        pageVo.setRows(pageInfo.getList());
        pageVo.setTotal(pageInfo.getTotal());

        return pageVo;
    }

    @Override
    public List<SysAuthorization> querySysAuthorizationByRoleId(Integer roleId) {
        return sysAuthorizationMapper.querySysAuthorizationByRoleId(roleId);
    }

    @Override
    public Boolean checkAuthenticate(Integer userId, String auCode) {
        List<SysAuthorization> sysAuthorizations = sysAuthorizationMapper.checkAuthenticate(userId, auCode);
        if(sysAuthorizations.size()>0){
            return true;
        }else{
            return false;
        }
    }
}
